<?php
//echo $this->Form->create();
$countries=$formData['countries'];
//debug($formData);
if(isset($formData['c_companies'])):
    $c_companies=$formData['c_companies'];
    $c_sites=$formData['c_sites'];
    $c_departments=$formData['c_departments'];
   
    $c_c_id=array_search($this->data['Dmdform']['company_title'],$c_companies,true);
    $c_s_id=array_search($this->data['Dmdform']['company_site'],$c_sites,true);
    $c_d_id=array_search($this->data['Dmdform']['company_department'],$c_departments);

?>
<fieldset>
    <legend>Company</legend>
<?php
    echo $this->Form->input('company_country',array('options'=>$countries,'label'=>array('text'=>__('Country',true),'class'=>'required'),'empty'=>'select','default'=>$this->data['Dmdform']['company_country'],'class'=>'selectCountry'));

    echo $this->Form->input('company_title',array('type'=>'select','options'=>$c_companies,'label'=>array('text'=>__('Company',true),'class'=>'required'),'empty'=>'select country','default'=>'1','class'=>'selectCompany'));

    echo $this->Form->input('company_site',array('options'=>$c_sites,'default'=>'3','label'=>array('text'=>__('Site',true),'class'=>'required'),'empty'=>'selectHHHHH','class'=>'selectSite'));

    echo $this->Form->input('company_department',array('type'=>'select','options'=>$c_departments,'label'=>array('text'=>__('Department',true),'class'=>'required'),'empty'=>'select site','default'=>'3','class'=>'selectDepartment'));
?>
    <div class="isHidden">
    <?php   echo $this->Form->input('company_id',array('type'=>'text','label'=>false,'empty'=>'0','class'=>'compId')); ?>
    </div>

</fieldset> 

<script type="text/javascript">
    $(document).ready(function(){
        $('.selectCompany').val(<?php echo $c_c_id  ?>);
        $('.selectSite').val(<?php echo $c_s_id  ?>);
        $('.selectDepartment').val(<?php echo $c_d_id  ?>);
    });
    

</script>
<?php else:  ?>
<fieldset>
    <legend>Company</legend>
<?php
    echo $this->Form->input('company_country',array('options'=>$countries,'label'=>array('text'=>__('Country',true),'class'=>'required'),'empty'=>'select','class'=>'selectCountry'));

    echo $this->Form->input('company_title',array('type'=>'select','label'=>array('text'=>__('Company',true),'class'=>'required'),'empty'=>'select country','class'=>'selectCompany'));

    echo $this->Form->input('company_site',array('type'=>'select','label'=>array('text'=>__('Site',true),'class'=>'required'),'empty'=>'select company','class'=>'selectSite'));

    echo $this->Form->input('company_department',array('type'=>'select','label'=>array('text'=>__('Department',true),'class'=>'required'),'empty'=>'select site','class'=>'selectDepartment'));
?>
    <div class="isHidden">
    <?php   echo $this->Form->input('company_id',array('type'=>'text','label'=>false,'empty'=>'0','class'=>'compId')); ?>
    </div>

</fieldset>  

<?php
endif;
//echo $this->Form->end();


?>